﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;

namespace YJKRevitStructModel
{
	public class HideWarningKit
	{
		public HideWarningKit(string transactionName)
		{
			this.m_TransactionName = transactionName;
		}

		public void OnFailuresProcessing(object sender, FailuresProcessingEventArgs e)
		{
			FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
			Document document = failuresAccessor.GetDocument();
			string transactionName = failuresAccessor.GetTransactionName();
			IList<FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages();
			if (failureMessages.Count == 0)
			{
				e.SetProcessingResult((FailureProcessingResult)0);
				return;
			}
			if (transactionName.Equals(this.m_TransactionName))
			{
				foreach (FailureMessageAccessor failureMessageAccessor in failureMessages)
				{
					if ((int)failureMessageAccessor.GetSeverity() != 1)
					{
						if (failureMessageAccessor.GetFailingElementIds().Count > 0)
						{
							IEnumerator<ElementId> enumerator2 = failureMessageAccessor.GetFailingElementIds().GetEnumerator();
							{
								while (enumerator2.MoveNext())
								{
									ElementId elementId = enumerator2.Current;
									if (!(document.GetElement(elementId) is Wall))
									{
										failuresAccessor.DeleteElements(new List<ElementId>
										{
											elementId
										});
									}
								}
								continue;
							}
						}
						e.SetProcessingResult((FailureProcessingResult)2);
						return;
					}
					failuresAccessor.DeleteWarning(failureMessageAccessor);
				}
				e.SetProcessingResult((FailureProcessingResult)1);
				return;
			}
			e.SetProcessingResult((FailureProcessingResult)0);
		}

		private string m_TransactionName = "";
	}
}
